package com.taotao.manage.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.manage.mapper.ItemMapper;
import com.taotao.manage.pojo.Item;
import com.taotao.manage.pojo.ItemDesc;

/**
 * 商品service
 * 
 * @author DuBo
 *
 */
@Service
public class ItemService extends BaseService<Item> {

	@Autowired
	private ItemMapper itemMapper;

	@Autowired
	private ItemDescService itemDescService;

	/**
	 * 保存商品信息和描述信息
	 * 
	 * @param item
	 * @param desc
	 * @return
	 */
	public Boolean saveItemAndDesc(Item item, String desc) {
		// 初始化状态
		item.setStatus(1);
		// 保证id为null， 数据库自动增长
		item.setId(null);
		Boolean flag = super.save(item);
		if (flag) {
			ItemDesc itemDesc = new ItemDesc();
			itemDesc.setItemDesc(desc);
			itemDesc.setItemId(item.getId());
		    flag = this.itemDescService.save(itemDesc);
		}
		return flag;
	}
	/**
	 * 更新商品信息
	 * @param item
	 * @param desc
	 * @return
	 */
	public Boolean updateItemAndDesc(Item item, String desc) {
				Boolean flag = super.updateByPrimaryKey(item);
				if (flag) {
					ItemDesc itemDesc = new ItemDesc();
					itemDesc.setItemDesc(desc);
					itemDesc.setItemId(item.getId());
				    flag = this.itemDescService.updateByPrimaryKey(itemDesc);
				}
				return flag;
	}

}
